import { setupLayouts } from "virtual:meta-layouts";
import { createRouter, createWebHistory } from "vue-router";
import generatedRoutes from "virtual:generated-pages";
import nProgress from "nprogress";

const routes = setupLayouts(generatedRoutes);
const router = createRouter({
  routes: routes,
  history: createWebHistory(),
});

router.beforeEach((to, from, next) => {
  const userStore = useUserStore();
  nProgress.start();
  if ((to.path !== "/" && userStore.isFirstVisit == true) || (to.path !== "/" && userStore.isCheckAccessPwdPass == false)) {
    next("/"); // 如果不是 index 页面，重定向到 index 页面
  } else {
    next(); // 否则正常进入 index 页面
  }
});
router.afterEach((to, from) => {
  nProgress.done(true);
});

export default router;
